<template>
	<view>
		<!-- <u-navbar :is-back="false" title="设置" title-color="#ffffff" :background="background"></u-navbar> -->
		<view class="content">
			<u-gap height="24" bg-color="#f3f4f6"></u-gap>
			<view class="order-list">
				<view v-if="orderList.length > 0">
					<block v-for="(item, index) in orderList" :key="index">
						<view class="order-item">
							<view class="order-item-sn">订单号:{{ item.orderSn }}</view>
							<view class="order-item-text">收货人:{{ item.receiver }}</view>
							<view class="order-item-text">手机号:{{ item.phoneNum }}</view>
							<view class="order-item-text">收货地址:{{ item.address }}</view>
							<view class="order-item-btn">
								<u-button class="u-m-l-16" type="success" size="medium" plain @click="tell(item.phoneNum)">一键拨号</u-button>
								<u-button class="u-m-l-16" type="primary" size="medium" plain @click="navigation(item.latitude, item.longitude)">导航到门店</u-button>
							</view>
						</view>
					</block>
				</view>
				<u-empty v-else text="没有相关信息" mode="data"></u-empty>
			</view>
			<u-gap height="24" bg-color="#f3f4f6"></u-gap>
			<view><u-toast ref="uToast" /></view>
		</view>
	</view>
</template>
<script>
export default {
	data() {
		return {
			background: {
				backgroundImage: 'linear-gradient(90deg, rgb(0,164,133), rgb(51,241,205))'
			},
			userInfo: {},
			//
			query: {
				sort: 'id,desc',
				page: 0,
				size: 20
			},
			orderList: []
		};
	},
	onLoad(option) {
		try {
			const token = uni.getStorageSync('token');
			if (token) {
				console.log(option);
				this.userInfo = uni.getStorageSync('userInfo');
				if(!this.userInfo){
					//#ifdef APP-PLUS
					uni.reLaunch({
						url: '/pages/login/index'
					});
					//#endif
					//#ifdef MP-WEIXIN
					uni.reLaunch({
						url: '/pages/login/xcxLogin'
					});
					//#endif
				}
				this.getOrderList();
			} else {
				//#ifdef APP-PLUS
				uni.reLaunch({
					url: '/pages/login/index'
				});
				//#endif
				//#ifdef MP-WEIXIN
				uni.reLaunch({
					url: '/pages/login/xcxLogin'
				});
				//#endif
			}
		} catch (e) {
			// error
		}
	},
	onShow() {},
	methods: {
		getOrderList() {
			let _t = this;
			_t.$u.api.getSjOrder().then(res => {
				console.log('getOrderList');
				console.log(res);
				if(res.statusCode == 200){
					_t.orderList = res.data;
				}else{
					setTimeout(() => {
						uni.navigateBack({
						    delta: 1
						});
					}, 3000)
				}
			});
		},
		tell(phoneNum) {
			if (phoneNum) {
				uni.makePhoneCall({
					phoneNumber: phoneNum //仅为示例
				});
			} else {
				this.$refs.uToast.show({
					title: '提示：该用户暂未填写手机号',
					type: 'error',
				});
			}
		},
		navigation(latitude,longitude) {
			if (latitude) {
				console.log(latitude)
				uni.openLocation({
				    latitude: Number(latitude),
				    longitude: Number(longitude),
				    success: function () {
				        console.log('success');
				    }
				});
			} else {
				this.$refs.uToast.show({
					title: '提示：该用户地址未填写完整',
					type: 'error',
				});
			}
			
		}
	}
};
</script>

<style lang="scss">
page {
	background-color: $u-bg-color;
}
.content {
	margin: 0 32rpx;
	.order-list {
		.order-item {
			background-color: #ffffff;
			margin-bottom: 24rpx;
			padding: 16rpx 24rpx;
			font-size: 24rpx;
			.order-item-btn {
				margin-top: 8rpx;
				text-align: center;
			}
			.order-item-sn {
				font-size: 28rpx;
				font-weight: bold;
				padding-bottom: 16rpx;
			}
			.order-item-text {
				font-size: 28rpx;
				padding-bottom: 16rpx;
			}
		}
	}
}
</style>
